package com.dylan.shot.common.util;

import net.sf.cglib.beans.BeanMap;

/**
 * Created by Dylan on 2017/9/12.
 */
public class ObjectUtils {

    public static  <T> void mergeProperties(T dest, T source) {
        if (!dest.getClass().getName().equals(source.getClass().getName())) {
            throw new RuntimeException("两个对象类型不一致");
        }
        BeanMap destBeanMap = BeanMap.create(dest);
        BeanMap sourceBeanMap = BeanMap.create(source);
        for (Object key : sourceBeanMap.keySet()) {
            Object val = sourceBeanMap.get(key);
            if (sourceBeanMap.get(key) != null) {
                destBeanMap.put(key, val);
            }
        }
    }
}
